﻿using DTcms.Common;
using DTcms.Web.Mvc.UI;
using System.Collections.Generic;
using System.Web.Mvc;

namespace DTcms.Web.Mvc.Areas.Admin.Controllers
{
    public class HomeController : Controller
    {
        protected Model.manager admin_info;//管理员信息
        protected ManageController baseAdmin = new ManageController();

        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (!baseAdmin.validateAdminPermission())
            {
                ViewBag.Title = "受限访问";
                ViewBag.Message = "抱歉, 系统设置了IP访问列表限制, 您无法访问本网站！";
                filterContext.Result = Content(baseAdmin.GetHTML("~/Areas/Admin/Views/Shared/Error.cshtml"));
                return;
            }
        }
        
        // GET: /Admin/Home/
        public ActionResult Index()
        {
            admin_info = baseAdmin.GetAdminInfo();
            if (admin_info == null)
            {
                return Redirect("Login");
            }
            //ViewBag.Langs = new BLL.Language_Code().AdminLanguages();
            //ViewBag.CurrentAdminLanguage = new BLL.Language_Code().AdminCurrentLanguage();
            return View(admin_info);
        }

        public ActionResult LogOff()
        {
            Session[DTKeys.SESSION_ADMIN_INFO] = null;
            Utils.WriteCookie("AdminName", "DTcms", -14400);
            Utils.WriteCookie("AdminPwd", "DTcms", -14400);
            return RedirectToAction("Login", "Home");
        }

        public ActionResult Login()
        {
            ViewBag.msgtip = "请输入用户名和密码";
            return View();
        }
    }
}
